package sortAlgorithm;

/**
 * 插入排序
 * 
 * @author YNS
 *
 */
public class InsertionSort {
	public static int[] sort(int[] source) {
		int temp = 0;
		int j;
		for (int i = 1; i < source.length; i++) {
			temp = source[i];
			for (j = i; j > 0; j--) {

				if (source[j - 1] > temp) {
					source[j] = source[j - 1];

					if (j == 1) {
						source[j - 1] = temp;
						break;
					}

				} else {
					source[j] = temp;
					break;
				}

//				 System.out.println(Arrays.toString(source));
			}
		}

		return source;
	}
}
